package br.ufpe.cin.imlm2.jbeat.paths;

import java.util.List;

import br.ufpe.cin.imlm2.jbeat.model.LightWeightClass;
import br.ufpe.cin.imlm2.jbeat.model.LightWeightMethod;
import br.ufpe.cin.imlm2.util.path.SimplePath;

public class SimpleExceptionPath extends SimplePath<LightWeightMethod> implements ExceptionPath {

	private LightWeightClass exception;
	private boolean isComplete;

	public SimpleExceptionPath( LightWeightClass exception ) {
		super();
		this.exception = exception;
		this.isComplete = true;
	}

	@Override
	public LightWeightClass getException() {
		return this.exception;
	}

	@Override
	public boolean isComplete() {
		return this.isComplete;
	}

	public void setComplete( boolean isComplete ) {
		this.isComplete = isComplete;
	}
	
	/**
	 * Wraps <code>pathAsList</code> and the exception <code>exception</code> in a
	 * SimpleExceptionPath object. The path is built considering that the last 
	 * <code>LightWeithMethod</code> in the list is the starting point of the path.
	 * @param pathAsList
	 * @param exception
	 * @return wrapped list as a SimpleExceptionPath object
	 * @throws IllegalArgumentException if either arguments is null
	 */
	public static SimpleExceptionPath wrap(List<LightWeightMethod> pathAsList, 
			LightWeightClass exception){
		if(pathAsList == null || exception == null)
			throw new IllegalArgumentException("Neither the list nor the exception can be null");
		SimpleExceptionPath path = new SimpleExceptionPath(exception);
		for (int i = pathAsList.size() - 1; i > -1; i--) {
			LightWeightMethod lightWeightMethod = pathAsList.get(i);
			path.addPoint(lightWeightMethod);
		}
		return path;
	}

}
